package com.szy.mvp_demo.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.szy.mvp_demo.Base.MyBaseAdapter;
import com.szy.mvp_demo.Entity.MessageListEntity;
import com.szy.mvp_demo.R;

/**
 * Created by Administrator on 2018/1/22 0022.
 */

public class ItemMessageAdapter extends MyBaseAdapter<MessageListEntity> {

    public ItemMessageAdapter(Context context) {
        super(context);
    }

    @Override
    public View setView(int position, View convertView, ViewGroup parent) {
        HoderView hoderView;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_message_list_adapter, null);
            hoderView = new HoderView(convertView);
            convertView.setTag(hoderView);
        } else {
            hoderView = (HoderView) convertView.getTag();
        }
        MessageListEntity entity = data.get(position);
        Glide.with(context).load(entity.getUrl()).into(hoderView.img);
        hoderView.tv_title.setText(entity.getTitle());
        hoderView.tv_content.setText(entity.getContent());
        hoderView.tv_time.setText(entity.getTime());
        return convertView;
    }

    private class HoderView {
        private TextView tv_title;
        private TextView tv_content;
        private TextView tv_time;
        private ImageView img;

        public HoderView(View view) {
            this.tv_title = view.findViewById(R.id.tv_item_message_title);
            this.tv_content = view.findViewById(R.id.tv_item_message_content);
            this.tv_time = view.findViewById(R.id.tv_item_message_time);
            this.img = view.findViewById(R.id.img_item_message_icon);
        }
    }

}
